home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c++
- Subject: Re: Problem with the ifstream class !!!
- Date: Sun, 14 Apr 1996 03:07:50 GMT
- Organization: Netcom
- Message-ID: <31706b14.276036299@nntp.ix.netcom.com>
- References: <4kc2si$8pp@web.cae.ca>
- NNTP-Posting-Host: ix-dc7-26.ix.netcom.com
- X-NETCOM-Date: Sat Apr 13 8:06:54 PM PDT 1996
- X-Newsreader: Forte Agent .99d/32.182
-
- Salim Mansouri <salim> wrote:
-
- > Hi,
- > I am using the ifstream class for reading an ASCII file.
- >
- > ex: char szTmp[255] = "";
- > ifstream fin("file.txt");
- >
- > while (fin)
- > {
- > fin.getline(szTmp, 250);
- > cout<<"The line is : "<<szTmp<<endl;
- > }
- >
- > The problem is that it reads twice the last line ????
- > Am i missing something.
- > N.B: I am compiling on SGI IRIX 5.3 .
-
- It's not reading the last line twice -- it's failing after reading the
- last line but you're ignoring that.
-
- while (fin)
-
- returns loops until fin has failed, not until it's about to fail. You
- want something like
-
- while (fin.getline(szTmp, 250))
- cout << "The line is : " << szTmp << endl;
-
-
- Michael M Rubenstein
-